export const useTableHight = () => {
  const set = () => {
    const tableBody = document.querySelector(".el-table__inner-wrapper")
    const emptyBlock = document.querySelector(".el-table__empty-block")

    if (!tableBody) return
    tableBody.style.minHeight = "300px"
    let top = 0
    const getParentTop = (dom) => {
      if (dom.nodeName === "BODY") {
        setTableHeight()
        return
      }
      top += dom.offsetTop
      getParentTop(dom.offsetParent)
    }

    const setTableHeight = () => {
      const restWidth = (document.body.clientWidth - 1440) / 20 // 消除px2rem的影响
      const height = `calc(100vh - ${top}px - 20pX - 40pX  - ${restWidth}px - 20pX )`
      tableBody.style.height = height
      if (emptyBlock) {
        emptyBlock.style.height = height
      }
    }

    getParentTop(tableBody)
  }
  onMounted(() => {
    setTimeout(() => {
      set()
    }, 0)
  })

  return {
    set
  }
}
